<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>核价基础台账</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
<div id="pageInTab" class="pageInTab">
		<div tabid="tabA" title="配置信息" lselected="true">
			<c:choose>
				<c:when test="${not empty prjPrdChangeFlag && prjPrdChangeFlag=='true'}">
					<iframe frameborder="0" name="tabA" id="tabA" src="<%=path%>/project/vehicle/toModifyPageHC.do?fromCddFlag=${fromCddFlag }&detailFlag=true&&id=${prjPrdId }&&prjId=${projectId}&&isDetail=${isDetail}"></iframe>
				</c:when>
				<c:otherwise>
					<iframe frameborder="0" name="tabA" id="tabA" src="<%=path%>/project/vehicle/toModifyPage.do?fromCddFlag=${fromCddFlag }&detailFlag=true&&id=${prjPrdId }&&prjId=${projectId}&&isDetail=${isDetail}"></iframe>
				</c:otherwise>
			</c:choose>
		</div>
</div>
	<form id="formSet1">
		<div class="fieldset1 tabel_col clearFix">
			<%-- <div class="fieldBox col_100">
		         <div class="label">核价信息</div>
		         <div class="field">
		         	<span>${previewCorePrcInfo }</span>
		         </div>
		    </div> --%>
		    
		    <div class="fieldBox col_50" <c:if test="${buOrgCd==00000008 }">style="display: none"</c:if>>
		         <div class="label" role="ligertip">（指导价/建议价格）-1</div>
		         <div class="field">
		              <span name="priceFormula" id="priceFormula">(${prjPrdPc }/${prdPc })-1</span>
		         </div>
		    </div>
		    <div class="fieldBox col_50" <c:if test="${buOrgCd==00000008 }">style="display: none"</c:if>>
		         <div class="label">设备浮动比例</div>
		         <div class="field">
		              <span name="priceCompare" id="priceCompare" class="requiredSymbol"></span>
		         </div>
		    </div>
		    <div class="fieldBox col_100">
		         <div class="label" role="ligertip">
		         	<c:if test="${buOrgCd!=00000008 }">校准货箱内部(长*宽*高)单位(毫米)</c:if>
		         	<c:if test="${buOrgCd==00000008 }">校准座位数</c:if>
	         	</div>
		         <div class="field">
		              <input name="lenWidHig" id="lenWidHig" type="text" class="ui-textbox" value="">
		         </div>
		    </div>
		    <div class="fieldBox col_100">
		         <div class="label">校准核价信息</div>
		         <div class="field">
		         	  <!-- 核价信息中带有回车,放到页面代码会导致页面加载错误 千万注意不要以 刀大括号 的形式把previewCorePrcInfo放到function代码中 注释也不可以 注意啊 犯了两次错误了!!!! -->
		         	  <!-- 万万没想到 在这里注释里写 刀大括号 也会影响页面加载  只能替换成汉字了-->
		              <textarea name="pricingInfo" id="pricingInfo" rows="3" class="l-textarea" value="${previewCorePrcInfo }" style="width:98%"
							<c:if test="${buOrgCd != '00000008' }">validate="{required:true}"</c:if>>${previewCorePrcInfo }</textarea>

					 <c:if test="${buOrgCd != '00000008' }"><span class="requiredSymbol">*</span></c:if>
		              <input name="corePrcBookId" id="corePrcBookId" type="hidden" value="">
		         </div>
		    </div>
		</div>
		<div class="btnsBox">
            <span id="saveBtn1" class="sq-button sq-button-round" onclick="savePriceInfo()">保存</span>
        </div>
	 </form>
</div>


<script type="text/javascript">
var _projectId = '${projectId}';//项目ID
var _proIntId = '${proIntId}';//流程实例ID
var _prjPrdId = '${prjPrdId}';//项目产品ID
var isDetail = '${isDetail}';

var prjPrdPc = '${prjPrdPc}';
var prdPc = '${prdPc}';

$(function(){
	var formSet1 = $('#formSet1').ligerForm({
        validate : true
	});
    //SET_popupIframeHeight();
    initTab();
	initPriceInfoBookData();
	if(isDetail==1){
		disabled();
	}

	var iframe = document.getElementById("tabA");
    iframe.onload = function(){
       iframe.setAttribute("style","height:"+iframe.contentWindow.document.body.scrollHeight+"px");
	}

	if(StringUtils.isNotEmpty(prjPrdPc)&&StringUtils.isNotEmpty(prdPc) && prdPc!=0){
		var priceCompare = Percentage(prjPrdPc,prdPc);
		if((prjPrdPc / prdPc * 100 - 100)>=0){
			$("#priceCompare").removeClass();
		}
		$("#priceCompare").html(priceCompare);
	}
});

function Percentage(number1, number2) { 
    return (number1 / number2 * 100 - 100 +"%");
   
}
function disabled(){
	if(liger.get("lenWidHig")){
		liger.get("lenWidHig").setDisabled(true);
	}
	$("#pricingInfo").setDisabled_ligerTextarea(true);
	$("#saveBtn1").hide();
}
function initTab(){
	pageInTab = $("#pageInTab").ligerTab({
        height: 'auto',
        contextmenu: false,
        minIframeHeight: 500,
	})
	SetIframe_height();
}
//定义父级调用事件
/* frameElement.dialog.onOk = function () {
	savePriceInfo();
}
frameElement.dialog.onCancel = function () {
     frameElement.dialog.close();
} */

//请求数据(参数:项目ID,流程实例ID)
function initPriceInfoBookData(){
	if(!_projectId || !_proIntId || !_prjPrdId){
		return;
	}
   	var _url = '<%=path%>/audit/audStandingBook/getAudCorePrcBook.do';
	$.ajax({
   		type: 'get',
   		dataType:'json',
   		data:{
   			projectId:_projectId,
   			proIntId:_proIntId,
   			prjPrdId:_prjPrdId
   		},
   		url: _url,
   		success:function(msg){
			if(msg.success == 1){
				setData(msg.data);//设置数据
			}else{
				$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
			}
		}
	});
}
//设置页面数据
function setData(data){
	$("#corePrcBookId").val(data.id);//核价台账ID
	var form = liger.get("formSet1");
	if(StringUtils.isEmpty(data.pricingInfo)){
	}else{
		$("#pricingInfo").val(data.pricingInfo); 
	}
	$("#lenWidHig").val(data.lenWidHig);
};

//保存核价基础台账
function savePriceInfo(){
	var form = liger.get("formSet1");
    if (!form.valid()) {
    	$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO , SQ_type: "warning" });
           return false;
	}
    var data = form.getData();
    var id = $("#corePrcBookId").val();
    var url='<%=path%>/audit/audStandingBook/add.do';
   	if(id != ""){
    	url = '<%=path%>/audit/audStandingBook/modify.do';
    	data["id"]= id;
    }
   	data["projectId"]= _projectId;//项目ID
   	data["proIntId"]= _proIntId;//流程实例ID
   	data["prjPrdId"]= _prjPrdId;//项目产品ID
   	data["bookTypeCd"]= AuditConstant.AUD_CORE_PRC_BOOK_TYP_CD;  //台账类型
    var wait_dialog;
    $.ajax({
		type: 'post',
		dataType:'json',
		data:data,
		url: url,
		beforeSend: function(){
	          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
	     },
		success:function(msg){
			 wait_dialog.close();
			 if(msg.success == 1){
				 $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
				 if(msg.data){
					 $("#corePrcBookId").val(msg.data);
				 }
				 //frameElement.dialog.close();
				 /* var TAB=top.mainApp.parentTab;
		         var currentTabid=TAB.getSelectedTabItemID();
	          	 top.tab.removeTabItem(currentTabid); */ 
			 }else{
				 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
			 }
		}
	});
}


</script>



</body>
</html>
